<template>
  <div class="blog-preview">
    <div class="row">
      <div class="preview col-12">
        <div class="preview-title">{{ blogData.title }}</div>
        <div class="preview-text">
          {{ removeMd(blogData.text).replaceAll("\n", " ") }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import global from "@/global";
import type { BlogData } from "@/global";

import removeMd from "remove-markdown";

const props = defineProps({
  blogPath: {
    type: String,
    default: "",
  },
});

let blogData = ref({} as BlogData);

let createPreview = () => {
  if (props.blogPath !== "") {
    global.getBlog(props.blogPath, (err, data) => {
      if (err) {
        throw err;
      }
      blogData.value = data;
    });
  }
};

onMounted(() => {
  createPreview();
});
</script>

<style scoped>
.preview {
}
</style>
